home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: extern consts
- Date: 20 Mar 1996 23:18:32 GMT
- Organization: Borland International
- Message-ID: <4iq3o8$rdh@druid.borland.com>
- References: <4idbcv$ue2@news7.erols.com> <314c2077.138956468@nntp.ix.netcom.com> <4ii7h9$bq6@news6.erols.com> <4iin9h$fdk@clarknet.clark.net>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <4iin9h$fdk@clarknet.clark.net>, gusty@clark.net says...
- >
- >Chris Cobb (ccobb@cseg.com) wrote:
- >: miker3@ix.netcom.com (Mike Rubenstein) wrote:
- >: >
- >: >It's not legal. extern const is legal, but in any compilation unit
- >: >that does not see the initializer the const variable is not a constant
- >: >expression.
- >: >
- >:
- >: Well, your comment makes sense. However, in a way it seem
- >: self-contradictory. If a const can be extern, then it no longer is a
- >: const: you've basically externed away constness.
- >
- >Huh? The word "const" means, fundamentally, "cannot be changed once
- >initialized". This holds just as true for an externally defined const as
- >any other. If you try the following in a module:
- >
- > extern const int iConst;
- > iConst = 5;
- >
- >it won't compile. So what do you mean by, "it no longer is a const"?
- >
-
- The confusion here is over the difference between a const object, that is, an
- object that cannot be changed once initialized, and a constant expression, that
- is, an expression that can be treated as a constant at compile time. For
- example:
-
- extern const size1;
- const size2 = 3;
-
- int array1[size1]; // illegal: size1 is not a constant expression
- int array2[size2]; // legal
-
- Both size1 and size2 are constants, 'cause that's the way they're declared. But
- size1 is not a "constant expression" in the sense that the language definition
- uses the term, because the compiler doesn't know what its value is.
- -- Pete
-
-